package com.bjdd.jdy.ui.wallet;

import com.bjdd.jdy.Constant;
import com.bjdd.jdy.util.JumpUtil;
import com.bjdd.jdy.util.L;
import com.bjdd.jdy.util.SpUtil;
import com.bjdd.jdy.util.T;

/**
 * Created by Administrator on 2017/5/10.
 */

public class WalletPresenter extends WalletContract.Presenter {
    @Override
    public void onStart() {
       /* String token = SpUtil.getToken();
        String carrierId = SpUtil.getUser().getCarrierId();
        getUserInfo(token,carrierId);*/
        if (SpUtil.getUser() == null || SpUtil.getUser().equals("") || SpUtil.getUser().getCarrierId() == null) {
            JumpUtil.toLogin(context);
            return;
        }
        L.d("onStart");
        rxManager.on(Constant.UPDATE_USER,msg -> getUserInfo());
        getUserInfo();
    }

    @Override
    public void getUserInfo() {
        String token = SpUtil.getToken();
        String userId = SpUtil.getUser().getCarrierId();
        showLoadingDialog(false);
        rxManager.add(model.getUserInfo(token,userId)
                .subscribe(result -> {
                    hideLoadingDialog();
                    if (!result.isError()){
                        SpUtil.setUser(result.getData());
                        view.userInfoSuccess(result.getData());
                    }else {
                        T.show(result.getMsg());
                    }
                },e -> {
                    hideLoadingDialog();
                }));
    }
}
